<!-- 需量查询 -->
<template>
  <div class='demandQuery'>
    <div class='operate card'>
      <div>
        <el-date-picker style="width:150px" v-model="s_time" :editable='false' :clearable="false" :type='d_type' :format="v_type" :value-format='v_type' :picker-options="pickerOptions" placeholder="选择开始时间">
        </el-date-picker>
      </div>
      <div>
        <el-select v-model="options_value" placeholder="" style="width:200px">
          <el-option v-for="item in options_data" :key="item.meterId" :label="item.meterName" :value="item.meterId">
          </el-option>
        </el-select>
      </div>
      <div>
        <el-button type="primary" @click='t_button'>查询</el-button>
      </div>
    </div>
    <el-row class='card' :gutter="0">
      <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" v-loading='isLoding3'>
        <Mtitle title='实时需量分布图'>
        </Mtitle>
        <!-- <Ecb width='100%' height='400px' :data="ecData" :maxdata="maxData"></Ecb> -->
        <ecscatter width='100%' height='500px' :ecdata='ecData' :maxdata="maxData"></ecscatter>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import Ecb from "./er_b.vue"
import Mtitle from '@/components/Mtitle'
import getweeks from '@/utils/weeks'
import day from '@/utils/day'
import dayjs from 'dayjs'
import tb from '@/components/table'
import ecscatter from '@/components/echarts/ec_scatter'

import './index.scss'
export default {
  name: 'demandQuery',
  data() {
    return {
      options_value: '',
      options_data: '',
      isLoding3: true,
      flag: false,
      ecData: '',
      maxData: '',
      s_time: '',
      d_type: "date",
      v_type: "yyyy-MM-dd",
      // 日月年
      t_value: 1,
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now() - 1000 * 60 * 60 * 24
        }
      },
      // ========== () ==========
      // ========== () ==========
      // ========== () ==========
      // ========== () ==========
      // ========== () ==========
      // ========== () ==========
      // ========== () ==========
      // ========== () ==========
      // ========== () ==========
      // ========== () ==========
      // ========== () ==========
      // ========== () ==========
      // ========== () ==========
      // ========== () ==========
      // ========== () ==========
    }
  },
  created() {
    this.s_time = dayjs().subtract(1, 'day').format('YYYY-MM-DD')
    // this.getaddElectric(1)
    this.findMeter()
  },
  methods: {
    // 每日用电成本分析-查询企业一级电表
    findMeter() {
      this.$axios.post(this.Eelec + '/web/elecCost/findMeter', {
        "custID": sessionStorage.getItem("custId"),
      }).then((res) => {
        if (res.data.code === 200) {
          if (res.data.data.length) {
            this.options_data = res.data.data
            this.options_value = res.data.data[0].meterId
            this.getaddElectric(1)
          }
        } else {

        }
      }).catch((err) => {
        console.log(err)
      })
    },
    getaddElectric(val) {
      var Time = ''
      if (val == 1) {
        Time = this.TodayTime
      } else {
        Time = this.productionDay
      }
      this.isLoding3 = true
      this.flag = false
      this.$axios.post(this.Eelec + '/web/elecCost/addElectric', {
        // "custId":sessionStorage.getItem("custId"),
        "custId": sessionStorage.getItem("custId"),
        "meterId": this.options_value,
        "time": this.s_time
      }).then((res) => {
        this.isLoding3 = false
        if (res.data.code == 200) {
          if (res.data.data != null) {
            var arr = []
            // res.data.data.loadDemand == null ? this.data1 = "--" : this.data1 = res.data.data.loadDemand
            // res.data.data.loadRate == null ? this.data2 = "--" : this.data2 = res.data.data.loadRate
            // res.data.data.capacityPrice == null ? this.data3 = "--" : this.data3 = res.data.data.capacityPrice
            // //res.data.data.demandPrice == null ? this.data4 = "--" : this.data4 = res.data.data.demandPrice
            // res.data.data.advice == null ? this.data5 = "--" : this.data5 = res.data.data.advice
            res.data.data.dataResp.map((item, i) => {
              arr.push(item.value)
              this.maxData = Math.max(...arr)
            })
            this.ecData = res.data.data
          } else {
            // this.data1 = "--"
            // this.data2 = "--"
            // this.data3 = "--"
            // //this.data4 = "--"
            // this.data5 = "--"
          }
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    t_button() {
      this.getaddElectric(1)
    }
    // ========== () ==========
    // ========== () ==========
    // ========== () ==========
    // ========== () ==========
    // ========== () ==========
    // ========== () ==========
    // ========== () ==========
    // ========== () ==========
    // ========== () ==========
    // ========== () ==========
  },
  mounted() { },
  components: {
    Mtitle,
    Ecb,
    ecscatter
  },
}

</script>

<style lang='' scoped>
</style>